package interfaceExample;

public class ExceptionTest {
	public static void main(String[] args) {
		/*
		ArrayList<Integer> arrayNub = new ArrayList<Integer>();
		int a = 5;
		try {
			System.out.println(arrayNub.get(-1)); //F2 on .get()
			a += 5;
		}catch(IndexOutOfBoundsException e){ //So now it works
			 System.out.println("The index that crashed the program: " + e.getMessage());
		}
  
		System.out.println(a);*/
		/*
		String[] stringArray = new String[]{"8", "9", "test", "10", "11"};
		for(int i=0; i<stringArray.length; i++){
			//System.out.println(Integer.parseInt(stringArray[i]));
			try {
				System.out.println(Integer.parseInt(stringArray[i]));  
			} catch(NumberFormatException e){
				System.out.println(e.getMessage());
			}
		}  */
		
		int[] array = new int[]{1, 3, 0, 10000};
		for(int i = 0; i<array.length; i++){
			try {
				System.out.println(testFuncTwo(array[i]));
			} catch(DivisionByZeroException e) {
				System.out.println("DIV BY ZERO " + e.getMessage());
			} catch(ArithmeticException e){
				System.out.println("ARITHMETIC " + e.getMessage());
			}
		}

	}
	
	public static double testFuncTwo(int i){
		return testFunc(i);
	}
	
	private static double testFunc(int i) {
		if(i == 0) throw new DivisionByZeroException(); //this line actually throws the exception
		if(i > 1000) throw new ArithmeticException("Number to large (" + i + ")");
		return  1.0/i;
	}
}